var G5_Apparatus = Window.extend({
	parent:null,
	apparatus:null,
	apparatus1:null,
	initAction:null,
	runningAction:null,
	runningAction1:null,
	runningAction2:null,
	runningAction3:null,
	status:true,
	ctor:function (parent,flow, tag) {
		this._super(parent,flow, tag);
		this.parent=parent;
		this.flow=flow;
	},
	initSp:function (){
		this.apparatus=new Button(this.rootNode,2,TAG_ITEM_APPARATUS4,"#apparatus_action/apparatus1.png",this.eventMenuCallback,this);
		this.apparatus.setPosition(cc.p(gg.c_width, gg.c_height));
		
		this.apparatus1=new Button(this.rootNode,2,TAG_ITEM_APPARATUS5,"#apparatus_action/apparatus5.png",this.eventMenuCallback,this);
		this.apparatus1.setPosition(cc.p(gg.c_width, gg.c_height));
		this.apparatus1.setVisible(false);
		if(teach_type == TAG_LEAD){
			this.chromatographic=new Button(this.rootNode,3,TAG_ITAM_CHROMATOGRAPHIC,"#equitment/chromatographic.png",this.eventMenuCallback,this);
			this.chromatographic.setPosition(cc.p(gg.c_width*0.998,gg.c_height*1.053));
			this.chromatographic.setVisible(false);
		}else{
			this.chromatographic=new Button(this.rootNode,3,TAG_ITAM_CHROMATOGRAPHIC,"#equitment/chromatographic1.png",this.eventMenuCallback,this);
			this.chromatographic.setPosition(cc.p(gg.c_width*0.998,gg.c_height*1.053));
			this.chromatographic.setVisible(false);
		}
		this.apparatus2=new Button(this.rootNode,2,TAG_ITEM_APPARATUS2,"#apparatus_top/apparatus_top1.png",this.eventMenuCallback,this);
		this.apparatus2.setPosition(cc.p(gg.c_width, gg.c_height));
		this.apparatus2.setVisible(false);
		
		this.apparatus_right=new Button(this.rootNode,2,TAG_ITEM_APPARATUS1,"#equitment/apparatus_right.png");
		this.apparatus_right.setPosition(cc.p(gg.c_width, gg.c_height));
		this.apparatus_right.setVisible(false);
		
		this.apparatus_open=new Button(this.rootNode,3,TAG_BUTTON_APPARATUSOPEN,"#equitment/apparatus_open.png",this.eventMenuCallback,this);
		this.apparatus_open.setPosition(cc.p(gg.c_width*0.92, gg.c_height*0.525));
		this.apparatus_open.setVisible(false);
		
		this.apparatus_close=new Button(this.rootNode,3,TAG_BUTTON_APPARATUSCLOSE,"#equitment/apparatus_open.png",this.eventMenuCallback,this);
		this.apparatus_close.setPosition(cc.p(gg.c_width*0.92, gg.c_height*0.525));
		this.apparatus_close.setVisible(false);
		
		this.apparatus3=new Button(this.rootNode,2,TAG_ITEM_APPARATUS7,"#apparatus_left/apparatus_left1.png",this.eventMenuCallback,this);
		this.apparatus3.setPosition(cc.p(gg.c_width, gg.c_height));
		this.apparatus3.setVisible(false);
		
		this.apparatus4=new Button(this.rootNode,2,TAG_ITEM_APPARATUS7,"#apparatus_left/apparatus_left5.png");
		this.apparatus4.setPosition(cc.p(gg.c_width, gg.c_height));
		this.apparatus4.setVisible(false);
		if(teach_type == TAG_LEAD){
		this.knob=new Button(this.rootNode,2,TAG_ITEM_KNOB,"#Knob/Knob_1.png",this.eventMenuCallback,this);
		this.knob.setPosition(cc.p(gg.c_width*0.827, gg.c_height*0.945));
		this.knob.setVisible(false);
		
		this.knob1=new Button(this.rootNode,2,TAG_ITEM_KNOB1,"#Knob/Knob_1.png",this.eventMenuCallback,this);
		this.knob1.setPosition(cc.p(gg.c_width*0.827, gg.c_height*0.9));
		this.knob1.setVisible(false);
		}else{
			this.knob=new Button(this.rootNode,2,TAG_ITEM_KNOB,"#Knob/Knob.png",this.eventMenuCallback,this);
			this.knob.setPosition(cc.p(gg.c_width*0.827, gg.c_height*0.945));
			this.knob.setVisible(false);

			this.knob1=new Button(this.rootNode,2,TAG_ITEM_KNOB1,"#Knob/Knob.png",this.eventMenuCallback,this);
			this.knob1.setPosition(cc.p(gg.c_width*0.827, gg.c_height*0.9));
			this.knob1.setVisible(false);
		}
		this.knob_action=new Button(this.rootNode,2,TAG_ITEM_KNOB1,"#Knob/Knob1.png",this.eventMenuCallback,this);
		this.knob_action.setPosition(cc.p(gg.c_width*0.55, gg.c_height));
		this.knob_action.setVisible(false);
		
		this.initAppActionOpen();
		this.initAppActionOpen1();
		this.initAppActionOpen2();
		this.initKnobAction();
	},
	initAppActionOpen:function(){
		var animFrames=[];
		for(var i=1;i<6;i++){
			var str="apparatus_action/apparatus"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.1)
		this.runningAction=cc.repeat(cc.animate(animation),1);
		this.runningAction.retain();
	},
	initAppActionOpen1:function(){
		var animFrames=[];
		for(var i=1;i<8;i++){
			var str="apparatus_top/apparatus_top"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.1)
		this.runningAction1=cc.repeat(cc.animate(animation),1);
		this.runningAction1.retain();
	},
	initAppActionOpen2:function(){
		var animFrames=[];
		for(var i=1;i<6;i++){
			var str="apparatus_left/apparatus_left"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.1)
		this.runningAction2=cc.repeat(cc.animate(animation),1);
		this.runningAction2.retain();
	},
	initKnobAction:function(){
		var animFrames=[];
		for(var i=1;i<8;i++){
			var str="Knob/Knob"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.1)
		this.runningAction3=cc.repeat(cc.animate(animation),1);
		this.runningAction3.retain();
	},
	eventMenuCallback:function(pSender){
		this.showDesc(pSender.getTag());
		if(cur_tool != TAG_BUTTON_HAND){
			// 描述
			return;
		}
		if(!this.flow.checkTag(pSender.getTag())){
			// 是否可以触发
			_.error();
			this.scene.tipLayer.updateScore(gg.score);
			return;
		} else {
			if(this.status==true){
				_.clever();
				this.scene.tipLayer.updateScore(gg.score);
			}
			
		}
		var action = this.flow.flow.action;
		var func=cc.callFunc(this.checkActionDone,this);
		var func1=cc.callFunc(this.close,this);
		var func2=cc.callFunc(this.next,this);
		switch(pSender.getTag()){
		case TAG_ITEM_APPARATUS4:
			if(this.status==true){
				if(action==ACTION_DO1){
					this.apparatus.runAction(cc.sequence(this.runningAction,func,func2));
				}
			}
			this.status=false;
			break;
		case TAG_ITAM_CHROMATOGRAPHIC:
			if(this.status==true){
				this.chromatographic.runAction(cc.sequence(func,func2));
			}
			this.status=false;
			break;
		case TAG_ITEM_APPARATUS5:
			if(this.status==true){
				this.apparatus1.runAction(cc.sequence(this.runningAction.reverse(),func,func1,func2));
			}
			this.status=false;
		  	break;
		case TAG_ITEM_APPARATUS2:
			if(this.status==true){
			this.apparatus2.runAction(cc.sequence(this.runningAction1,func,func1,func2));
			}
			this.status=false;
			break;
		case TAG_BUTTON_APPARATUSOPEN:
			this.flow.next();
			this.apparatus_open.setVisible(false);
			this.parent.apparatus1.setVisible(false);
			this.parent.display.setVisible(true);
			this.parent.apparatus2.setVisible(true);
			this.close();
			break;
		case TAG_BUTTON_APPARATUSCLOSE:
			this.flow.next();
			this.apparatus_close.setVisible(false);
			this.parent.apparatus3.setSpriteFrame("apparatus_left/apparatus_left6.png");
			this.close();
			break;
		case TAG_ITEM_APPARATUS7:
			if(this.status==true){
			if(action==ACTION_DO1){
				this.apparatus3.runAction(cc.sequence(this.runningAction2,func,func2));
			}
		}
			this.status=false;
			break;
		case TAG_ITEM_KNOB:
			if(this.status==true){
				this.knob.setVisible(false);
				this.knob_action.setVisible(true);
				this.knob.runAction(cc.sequence(func,cc.delayTime(2),cc.callFunc(function() {
					this.knob_action.setVisible(false);
					this.knob1.setVisible(true);
				},this),func2));
			}
			break;
		case TAG_ITEM_KNOB1:
			if(this.status=true){
				this.knob1.setVisible(false);
				this.knob_action.setVisible(true);
				this.knob1.runAction(cc.sequence(func,cc.delayTime(2),cc.callFunc(function() {
					this.knob_action.setVisible(false);
				},this),func1,func2));
			}
			break;
		default:
			break;
		}
	},
	checkActionDone:function(pSender){
		var tag=pSender.getTag();
		var action=this.flow.flow.action;
		if(tag==TAG_ITEM_APPARATUS4){
			if(action==ACTION_DO1){
				this.apparatus.setVisible(false);
				this.apparatus1.setVisible(true);
				this.chromatographic.setVisible(true);
			}
		}else if(tag==TAG_ITAM_CHROMATOGRAPHIC){
			this.chromatographic.setVisible(false);
		}else if(tag==TAG_ITEM_APPARATUS5){
			this.apparatus1.setVisible(true);
		}else if(tag==TAG_ITEM_APPARATUS2){
			this.parent.apparatus.setVisible(false);
			this.parent.apparatus1.setVisible(true);
		}else if(tag==TAG_ITEM_APPARATUS7){
			if(action==ACTION_DO1){
				this.parent.apparatus2.setVisible(false);
				this.parent.apparatus3.setVisible(true);
				this.parent.display.setVisible(true);
				this.parent.display.setPosition(cc.p(gg.c_width*0.945, gg.c_height*1.155));
				this.knob.setVisible(true);
			}
		}else if(tag==TAG_ITEM_KNOB){
			this.knob_action.runAction(this.runningAction3);
		}else if(tag==TAG_ITEM_KNOB1){
			this.knob_action.runAction(this.runningAction3);
		}
		this.status=true;
	},
	next:function(){
		this.flow.next();
	}
});